package me.zhengjie.gas.proto.recv;


import me.zhengjie.gas.proto.TankerComm;


/**
 * 在加油机加油状态回复实时信息，实时加油信息命令BA
 */
public class BAComm extends TankerComm {

    private String fuelAmount;  // 加油量
    private String fuelCost;  // 加油金额
    private String unitPrice;  // 单价
    private int status;  // 状态字

    public BAComm() {
        Cmd = (byte) 0xBA;
    }

    @Override
    protected boolean decode() {
        byte[] data = getDATA();

        fuelAmount = byteToBcdString(data, 1, 4);
        fuelCost = byteToBcdString(data, 5, 4);
        unitPrice = byteToBcdString(data, 9, 3);
        status = (0xFF & data[12]);

        return true;
    }

    @Override
    public byte[] encode() {
        byte[] data = new byte[13];
        data[0] = Cmd;
        byte[] bytes = stringToBcdByteArray(fuelAmount, 4);
        System.arraycopy(bytes, 0, data, 1, bytes.length);

        bytes = stringToBcdByteArray(fuelCost, 4);
        System.arraycopy(bytes, 0, data, 5, bytes.length);

        bytes = stringToBcdByteArray(unitPrice, 3);
        System.arraycopy(bytes, 0, data, 9, bytes.length);

        data[12] = (byte) status;

        setDATA(data);
        return super.encode();
    }

    @Override
    public String toString() {
        String str = "加油量：" + fuelAmount + "\n" +
                "加油金额：" + fuelCost + "\n" +
                "单价：" + unitPrice + "\n" +
                "状态字：" + status + "\n";
        return str;
    }

    public String getFuelAmount() {
        return fuelAmount;
    }

    public void setFuelAmount(String fuelAmount) {
        this.fuelAmount = fuelAmount;
    }

    public String getFuelCost() {
        return fuelCost;
    }

    public void setFuelCost(String fuelCost) {
        this.fuelCost = fuelCost;
    }

    public String getUnitPrice() {
        return unitPrice;
    }

    public void setUnitPrice(String unitPrice) {
        this.unitPrice = unitPrice;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }
}
